<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="text/css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
    <link rel="stylesheet" href="../css/ol.css" type="text/css">
    <link rel="stylesheet" href="./resources/layout.css" type="text/css">
    
    
    <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
    <title>Animation example</title>
  </head>
  <body>

    <header class="navbar" role="navigation">
      <div class="container" id="navbar-inner-container">
        <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png">&nbsp;OpenLayers 3 Examples</a>
      </div>
    </header>

    <div class="container-fluid">

      <div class="row-fluid">
  <div class="span12">
    <div id="map" class="map"></div>
  </div>
</div>
<div class="row-fluid">
  <div class="span12">
    <button id="rotate-left" title="Rotate clockwise">↻</button>
    <button id="rotate-right" title="Rotate counterclockwise">↺</button>
    <button id="rotate-around-rome">Rotate around Rome</button>
    <button id="pan-to-london">Pan to London</button>
    <button id="elastic-to-moscow">Elastic to Moscow</button>
    <button id="bounce-to-istanbul">Bounce to Istanbul</button>
    <button id="spin-to-rome">Spin to Rome</button>
    <button id="fly-to-bern">Fly to Bern</button>
    <button id="spiral-to-madrid">Spiral to Madrid</button>
  </div>
</div>


      <div class="row-fluid">
        <div class="span12">
          <h4 id="title">Animation example</h4>
          <p id="shortdesc">Demonstrates animated pan, zoom, and rotation.</p>
          <div id="docs"><p>This example shows how to use the beforeRender function on the Map to run one or more animations.</p>
</div>
          <div id="tags">animation</div>
          <div id="api-links">Related API documentation: <ul class="inline"><li><a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a></li>,<li><a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a></li>,<li><a href="../apidoc/ol.animation.html" title="API documentation for ol.animation">ol.animation</a></li>,<li><a href="../apidoc/ol.control.html" title="API documentation for ol.control">ol.control</a></li>,<li><a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a></li>,<li><a href="../apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a></li>,<li><a href="../apidoc/ol.source.OSM.html" title="API documentation for ol.source.OSM">ol.source.OSM</a></li></ul></div>
        </div>
      </div>

      <div class="row-fluid">
        <div id="source-controls">
          <a id="copy-button"><i class="fa fa-clipboard"></i> Copy</a>
          <a id="jsfiddle-button"><i class="fa fa-jsfiddle"></i> Edit</a>
        </div>
        <form method="POST" id="jsfiddle-form" target="_blank" action="http://jsfiddle.net/api/post/jquery/1.11.0/">
          <textarea class="hidden" name="js">// from https://github.com/DmitryBaranovskiy/raphael
function bounce(t) {
  var s &#x3D; 7.5625, p &#x3D; 2.75, l;
  if (t &lt; (1 / p)) {
    l &#x3D; s * t * t;
  } else {
    if (t &lt; (2 / p)) {
      t -&#x3D; (1.5 / p);
      l &#x3D; s * t * t + 0.75;
    } else {
      if (t &lt; (2.5 / p)) {
        t -&#x3D; (2.25 / p);
        l &#x3D; s * t * t + 0.9375;
      } else {
        t -&#x3D; (2.625 / p);
        l &#x3D; s * t * t + 0.984375;
      }
    }
  }
  return l;
}

// from https://github.com/DmitryBaranovskiy/raphael
function elastic(t) {
  return Math.pow(2, -10 * t) * Math.sin((t - 0.075) * (2 * Math.PI) / 0.3) + 1;
}

var london &#x3D; ol.proj.fromLonLat([-0.12755, 51.507222]);
var moscow &#x3D; ol.proj.fromLonLat([37.6178, 55.7517]);
var istanbul &#x3D; ol.proj.fromLonLat([28.9744, 41.0128]);
var rome &#x3D; ol.proj.fromLonLat([12.5, 41.9]);
var bern &#x3D; ol.proj.fromLonLat([7.4458, 46.95]);
var madrid &#x3D; ol.proj.fromLonLat([-3.683333, 40.4]);

var view &#x3D; new ol.View({
  // the view&#x27;s initial state
  center: istanbul,
  zoom: 6
});

var map &#x3D; new ol.Map({
  layers: [
    new ol.layer.Tile({
      preload: 4,
      source: new ol.source.OSM()
    })
  ],
  // Improve user experience by loading tiles while animating. Will make
  // animations stutter on mobile or slow devices.
  loadTilesWhileAnimating: true,
  target: &#x27;map&#x27;,
  controls: ol.control.defaults({
    attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
      collapsible: false
    })
  }),
  view: view
});

var rotateLeft &#x3D; document.getElementById(&#x27;rotate-left&#x27;);
rotateLeft.addEventListener(&#x27;click&#x27;, function() {
  var rotateLeft &#x3D; ol.animation.rotate({
    duration: 2000,
    rotation: -4 * Math.PI
  });
  map.beforeRender(rotateLeft);
}, false);
var rotateRight &#x3D; document.getElementById(&#x27;rotate-right&#x27;);
rotateRight.addEventListener(&#x27;click&#x27;, function() {
  var rotateRight &#x3D; ol.animation.rotate({
    duration: 2000,
    rotation: 4 * Math.PI
  });
  map.beforeRender(rotateRight);
}, false);

var rotateAroundRome &#x3D; document.getElementById(&#x27;rotate-around-rome&#x27;);
rotateAroundRome.addEventListener(&#x27;click&#x27;, function() {
  var currentRotation &#x3D; view.getRotation();
  var rotateAroundRome &#x3D; ol.animation.rotate({
    anchor: rome,
    duration: 1000,
    rotation: currentRotation
  });
  map.beforeRender(rotateAroundRome);
  view.rotate(currentRotation + (Math.PI / 2), rome);
}, false);

var panToLondon &#x3D; document.getElementById(&#x27;pan-to-london&#x27;);
panToLondon.addEventListener(&#x27;click&#x27;, function() {
  var pan &#x3D; ol.animation.pan({
    duration: 2000,
    source: /** @type {ol.Coordinate} */ (view.getCenter())
  });
  map.beforeRender(pan);
  view.setCenter(london);
}, false);

var elasticToMoscow &#x3D; document.getElementById(&#x27;elastic-to-moscow&#x27;);
elasticToMoscow.addEventListener(&#x27;click&#x27;, function() {
  var pan &#x3D; ol.animation.pan({
    duration: 2000,
    easing: elastic,
    source: /** @type {ol.Coordinate} */ (view.getCenter())
  });
  map.beforeRender(pan);
  view.setCenter(moscow);
}, false);

var bounceToIstanbul &#x3D; document.getElementById(&#x27;bounce-to-istanbul&#x27;);
bounceToIstanbul.addEventListener(&#x27;click&#x27;, function() {
  var pan &#x3D; ol.animation.pan({
    duration: 2000,
    easing: bounce,
    source: /** @type {ol.Coordinate} */ (view.getCenter())
  });
  map.beforeRender(pan);
  view.setCenter(istanbul);
}, false);

var spinToRome &#x3D; document.getElementById(&#x27;spin-to-rome&#x27;);
spinToRome.addEventListener(&#x27;click&#x27;, function() {
  var duration &#x3D; 2000;
  var start &#x3D; +new Date();
  var pan &#x3D; ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  });
  var rotate &#x3D; ol.animation.rotate({
    duration: duration,
    rotation: 2 * Math.PI,
    start: start
  });
  map.beforeRender(pan, rotate);
  view.setCenter(rome);
}, false);

var flyToBern &#x3D; document.getElementById(&#x27;fly-to-bern&#x27;);
flyToBern.addEventListener(&#x27;click&#x27;, function() {
  var duration &#x3D; 2000;
  var start &#x3D; +new Date();
  var pan &#x3D; ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  });
  var bounce &#x3D; ol.animation.bounce({
    duration: duration,
    resolution: 4 * view.getResolution(),
    start: start
  });
  map.beforeRender(pan, bounce);
  view.setCenter(bern);
}, false);

var spiralToMadrid &#x3D; document.getElementById(&#x27;spiral-to-madrid&#x27;);
spiralToMadrid.addEventListener(&#x27;click&#x27;, function() {
  var duration &#x3D; 2000;
  var start &#x3D; +new Date();
  var pan &#x3D; ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  });
  var bounce &#x3D; ol.animation.bounce({
    duration: duration,
    resolution: 2 * view.getResolution(),
    start: start
  });
  var rotate &#x3D; ol.animation.rotate({
    duration: duration,
    rotation: -4 * Math.PI,
    start: start
  });
  map.beforeRender(pan, bounce, rotate);
  view.setCenter(madrid);
}, false);
</textarea>
          <textarea class="hidden" name="css"></textarea>
          <textarea class="hidden" name="html">&lt;div class&#x3D;&quot;row-fluid&quot;&gt;
  &lt;div class&#x3D;&quot;span12&quot;&gt;
    &lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;div class&#x3D;&quot;row-fluid&quot;&gt;
  &lt;div class&#x3D;&quot;span12&quot;&gt;
    &lt;button id&#x3D;&quot;rotate-left&quot; title&#x3D;&quot;Rotate clockwise&quot;&gt;↻&lt;/button&gt;
    &lt;button id&#x3D;&quot;rotate-right&quot; title&#x3D;&quot;Rotate counterclockwise&quot;&gt;↺&lt;/button&gt;
    &lt;button id&#x3D;&quot;rotate-around-rome&quot;&gt;Rotate around Rome&lt;/button&gt;
    &lt;button id&#x3D;&quot;pan-to-london&quot;&gt;Pan to London&lt;/button&gt;
    &lt;button id&#x3D;&quot;elastic-to-moscow&quot;&gt;Elastic to Moscow&lt;/button&gt;
    &lt;button id&#x3D;&quot;bounce-to-istanbul&quot;&gt;Bounce to Istanbul&lt;/button&gt;
    &lt;button id&#x3D;&quot;spin-to-rome&quot;&gt;Spin to Rome&lt;/button&gt;
    &lt;button id&#x3D;&quot;fly-to-bern&quot;&gt;Fly to Bern&lt;/button&gt;
    &lt;button id&#x3D;&quot;spiral-to-madrid&quot;&gt;Spiral to Madrid&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;
</textarea>
          <input type="hidden" name="wrap" value="l">
          <input type="hidden" name="resources" value="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css,https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js,http://openlayers.org/en/v3.11.1/css/ol.css,http://openlayers.org/en/v3.11.1/build/ol.js">
        </form>
        <pre><code id="example-source" class="language-markup">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Animation example&lt;/title&gt;
&lt;script src="https://code.jquery.com/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
&lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="http://openlayers.org/en/v3.11.1/css/ol.css" type="text/css"&gt;
&lt;script src="http://openlayers.org/en/v3.11.1/build/ol.js"&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div class="container-fluid"&gt;

&lt;div class&#x3D;&quot;row-fluid&quot;&gt;
  &lt;div class&#x3D;&quot;span12&quot;&gt;
    &lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;div class&#x3D;&quot;row-fluid&quot;&gt;
  &lt;div class&#x3D;&quot;span12&quot;&gt;
    &lt;button id&#x3D;&quot;rotate-left&quot; title&#x3D;&quot;Rotate clockwise&quot;&gt;↻&lt;/button&gt;
    &lt;button id&#x3D;&quot;rotate-right&quot; title&#x3D;&quot;Rotate counterclockwise&quot;&gt;↺&lt;/button&gt;
    &lt;button id&#x3D;&quot;rotate-around-rome&quot;&gt;Rotate around Rome&lt;/button&gt;
    &lt;button id&#x3D;&quot;pan-to-london&quot;&gt;Pan to London&lt;/button&gt;
    &lt;button id&#x3D;&quot;elastic-to-moscow&quot;&gt;Elastic to Moscow&lt;/button&gt;
    &lt;button id&#x3D;&quot;bounce-to-istanbul&quot;&gt;Bounce to Istanbul&lt;/button&gt;
    &lt;button id&#x3D;&quot;spin-to-rome&quot;&gt;Spin to Rome&lt;/button&gt;
    &lt;button id&#x3D;&quot;fly-to-bern&quot;&gt;Fly to Bern&lt;/button&gt;
    &lt;button id&#x3D;&quot;spiral-to-madrid&quot;&gt;Spiral to Madrid&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;script&gt;
// from https://github.com/DmitryBaranovskiy/raphael
function bounce(t) {
  var s &#x3D; 7.5625, p &#x3D; 2.75, l;
  if (t &lt; (1 / p)) {
    l &#x3D; s * t * t;
  } else {
    if (t &lt; (2 / p)) {
      t -&#x3D; (1.5 / p);
      l &#x3D; s * t * t + 0.75;
    } else {
      if (t &lt; (2.5 / p)) {
        t -&#x3D; (2.25 / p);
        l &#x3D; s * t * t + 0.9375;
      } else {
        t -&#x3D; (2.625 / p);
        l &#x3D; s * t * t + 0.984375;
      }
    }
  }
  return l;
}

// from https://github.com/DmitryBaranovskiy/raphael
function elastic(t) {
  return Math.pow(2, -10 * t) * Math.sin((t - 0.075) * (2 * Math.PI) / 0.3) + 1;
}

var london &#x3D; ol.proj.fromLonLat([-0.12755, 51.507222]);
var moscow &#x3D; ol.proj.fromLonLat([37.6178, 55.7517]);
var istanbul &#x3D; ol.proj.fromLonLat([28.9744, 41.0128]);
var rome &#x3D; ol.proj.fromLonLat([12.5, 41.9]);
var bern &#x3D; ol.proj.fromLonLat([7.4458, 46.95]);
var madrid &#x3D; ol.proj.fromLonLat([-3.683333, 40.4]);

var view &#x3D; new ol.View({
  // the view&#x27;s initial state
  center: istanbul,
  zoom: 6
});

var map &#x3D; new ol.Map({
  layers: [
    new ol.layer.Tile({
      preload: 4,
      source: new ol.source.OSM()
    })
  ],
  // Improve user experience by loading tiles while animating. Will make
  // animations stutter on mobile or slow devices.
  loadTilesWhileAnimating: true,
  target: &#x27;map&#x27;,
  controls: ol.control.defaults({
    attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
      collapsible: false
    })
  }),
  view: view
});

var rotateLeft &#x3D; document.getElementById(&#x27;rotate-left&#x27;);
rotateLeft.addEventListener(&#x27;click&#x27;, function() {
  var rotateLeft &#x3D; ol.animation.rotate({
    duration: 2000,
    rotation: -4 * Math.PI
  });
  map.beforeRender(rotateLeft);
}, false);
var rotateRight &#x3D; document.getElementById(&#x27;rotate-right&#x27;);
rotateRight.addEventListener(&#x27;click&#x27;, function() {
  var rotateRight &#x3D; ol.animation.rotate({
    duration: 2000,
    rotation: 4 * Math.PI
  });
  map.beforeRender(rotateRight);
}, false);

var rotateAroundRome &#x3D; document.getElementById(&#x27;rotate-around-rome&#x27;);
rotateAroundRome.addEventListener(&#x27;click&#x27;, function() {
  var currentRotation &#x3D; view.getRotation();
  var rotateAroundRome &#x3D; ol.animation.rotate({
    anchor: rome,
    duration: 1000,
    rotation: currentRotation
  });
  map.beforeRender(rotateAroundRome);
  view.rotate(currentRotation + (Math.PI / 2), rome);
}, false);

var panToLondon &#x3D; document.getElementById(&#x27;pan-to-london&#x27;);
panToLondon.addEventListener(&#x27;click&#x27;, function() {
  var pan &#x3D; ol.animation.pan({
    duration: 2000,
    source: /** @type {ol.Coordinate} */ (view.getCenter())
  });
  map.beforeRender(pan);
  view.setCenter(london);
}, false);

var elasticToMoscow &#x3D; document.getElementById(&#x27;elastic-to-moscow&#x27;);
elasticToMoscow.addEventListener(&#x27;click&#x27;, function() {
  var pan &#x3D; ol.animation.pan({
    duration: 2000,
    easing: elastic,
    source: /** @type {ol.Coordinate} */ (view.getCenter())
  });
  map.beforeRender(pan);
  view.setCenter(moscow);
}, false);

var bounceToIstanbul &#x3D; document.getElementById(&#x27;bounce-to-istanbul&#x27;);
bounceToIstanbul.addEventListener(&#x27;click&#x27;, function() {
  var pan &#x3D; ol.animation.pan({
    duration: 2000,
    easing: bounce,
    source: /** @type {ol.Coordinate} */ (view.getCenter())
  });
  map.beforeRender(pan);
  view.setCenter(istanbul);
}, false);

var spinToRome &#x3D; document.getElementById(&#x27;spin-to-rome&#x27;);
spinToRome.addEventListener(&#x27;click&#x27;, function() {
  var duration &#x3D; 2000;
  var start &#x3D; +new Date();
  var pan &#x3D; ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  });
  var rotate &#x3D; ol.animation.rotate({
    duration: duration,
    rotation: 2 * Math.PI,
    start: start
  });
  map.beforeRender(pan, rotate);
  view.setCenter(rome);
}, false);

var flyToBern &#x3D; document.getElementById(&#x27;fly-to-bern&#x27;);
flyToBern.addEventListener(&#x27;click&#x27;, function() {
  var duration &#x3D; 2000;
  var start &#x3D; +new Date();
  var pan &#x3D; ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  });
  var bounce &#x3D; ol.animation.bounce({
    duration: duration,
    resolution: 4 * view.getResolution(),
    start: start
  });
  map.beforeRender(pan, bounce);
  view.setCenter(bern);
}, false);

var spiralToMadrid &#x3D; document.getElementById(&#x27;spiral-to-madrid&#x27;);
spiralToMadrid.addEventListener(&#x27;click&#x27;, function() {
  var duration &#x3D; 2000;
  var start &#x3D; +new Date();
  var pan &#x3D; ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  });
  var bounce &#x3D; ol.animation.bounce({
    duration: duration,
    resolution: 2 * view.getResolution(),
    start: start
  });
  var rotate &#x3D; ol.animation.rotate({
    duration: duration,
    rotation: -4 * Math.PI,
    start: start
  });
  map.beforeRender(pan, bounce, rotate);
  view.setCenter(madrid);
}, false);

&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
      </div>
    </div>

    <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="./resources/common.js"></script>
    <script src="./resources/prism/prism.min.js"></script>
    <script src="loader.js?id=animation"></script>

  </body>
</html>
